package com.example.com.daervideo.fragments;

import android.databinding.ViewDataBinding;

import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
import com.lcodecore.tkrefreshlayout.header.progresslayout.ProgressLayout;

import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.base.BaseViewModel;

public abstract class BaseListFragmnet<V extends ViewDataBinding, T extends BaseViewModel> extends BaseFragment<V, T> {
    protected int page = 1;
    protected int pageSize = 15;

    @Override
    public void initData() {
        super.initData();
        TwinklingRefreshLayout refreshLayout = getRefreshLayout();
        ProgressLayout progressLayout = new ProgressLayout(context);
        refreshLayout.setHeaderView(progressLayout);
        refreshLayout.setOnRefreshListener(new RefreshListenerAdapter() {
            @Override
            public void onLoadMore(TwinklingRefreshLayout refreshLayout) {
                super.onLoadMore(refreshLayout);
                page++;
                getNetData(page, pageSize);
            }

            @Override
            public void onRefresh(TwinklingRefreshLayout refreshLayout) {
                super.onRefresh(refreshLayout);
                page = 1;
                getNetData(page, pageSize);
            }
        });
    }

    protected abstract void getNetData(int page, int pageSize);

    protected abstract TwinklingRefreshLayout getRefreshLayout();

}
